<?php
namespace Admin\Controller;
use Think\Controller;
class AdminController extends Controller {
 private $pagesize='1';





       public function login(){

//       if(!isset($_POST['submit'])){
//               exit('非法访问!');
//       }

        if($_POST['submit']){
            $userName=$_POST['name'];
            $password=$_POST['password'];
            $data =array(
                'userName' => $userName,
                'password'  => $password,
            );  //定义参数
            $url = INTERFACE_ADDRESS.'/api/user/bLogin';


            $response = $this->tocurlPost($url, $header='',$data);
            $info = json_decode($response, true);
//            print_r($info);exit;





            if($info['code']=='200'){//登录成功
                $loginName=$info['data']['merchantName'];
                session('loginName',$loginName);

                $bAccessToken = $info['data']['bAccessToken'];
//                var_dump($bAccessToken);exit;
                session('bAccessToken',$bAccessToken);
//                header('Location:http://'.WORK_MODE.'/Bside/Admin/Admin/contIndex');

                header('Location:http://'. $_SERVER['HTTP_HOST'].'/Admin/Admin/contIndex');
            }else{
//                echo "<script>alert('账户或密码错误')</script>";
                exit('登录失败！点击此处 <a href="javascript:history.back(-1);">返回</a> 重试');
            }

        }




//注销登录
           if($_GET['action'] == "logout"){
               unset($_SESSION['bAccessToken']);
               unset($_SESSION['loginName']);


//               echo '注销登录成功！点击此处 <a href="http://localhost/Bside/Admin/Admin/login">登录</a>';
               exit;
           }



           $this->display('login');

        }


        public function logout(){
            session_start();    //启动会话
            session_unset();    //删除会话
            session_destroy();  //结束会话
//            header("location: http://localhost/Bside/index.php/Admin/Admin/login");
            header('Location:http://'. $_SERVER['HTTP_HOST'].'/Admin/Admin/login');
        }








//首页内容
    public function index(){
//           print_r($_SERVER['HTTP_HOST']);
           var_dump($_SESSION['loginName']);

        $this->assign('loginName',$_SESSION['loginName']);
        $this->display('index');
    }

//保全统计首页内容
        public function contIndex(){



        var_dump($_SESSION['bAccessToken']);

            $url = INTERFACE_ADDRESS.'/api/preserve/bStatistics ';
//            $data = array('bAccessToken=>'.$_SESSION['bAccessToken']);
            $header = array('bAccessToken:'.$_SESSION['bAccessToken'],'language:zh','region:GZ');
            $response = $this->tocurlGet($url, $header);
            $file_contents = json_decode($response, true);
//            var_dump($file_contents);die;

            print_r($file_contents);

            $contractNum=$file_contents['data']['contract'];
            $basicsNum=$file_contents['data']['basics'];



            $this->assign('contractNum',$contractNum);
            $this->assign('basicsNum',$basicsNum);
            $this->assign('loginName',$_SESSION['loginName']);

            $this->display('cont_index');
        }




    //合同列表
    public function contractManage(){

//        var_dump($_SESSION['bAccessToken']);
//
//        checkLogin();
//
//
//        $page=$_REQUEST['pages']?(int)$_REQUEST['pages']:1;
//            $url = INTERFACE_ADDRESS.'/api/contract/contractTemplateList?pageSize='.$this->pagesize.'&pages='.$page;
////        $file_contents = json_decode(file_get_contents($url),true);
//
////        $url = INTERFACE_ADDRESS.'api/preserve/bStatistics ';
////            $data = array('bAccessToken=>'.$_SESSION['bAccessToken']);
//        $header = array('bAccessToken:'.$_SESSION['bAccessToken'],'language:zh','region:GZ');
//        $response = $this->tocurlGet($url, $header);
//        $file_contents = json_decode($response, true);
//
//        print_r($file_contents);
//
//        $totalPage=$file_contents['data']['pages'];
//        if($page<1||$page==null||!is_numeric($page))$page=1;
//        if($page>=$totalPage)$page=$totalPage;
//        $page=  showPage($page,$totalPage,$url='http://xbb.qecity.com/Admin/Admin/contractManage.html',$this->pagesize,$file_contents['data']['total']);
//
//        if($totalPage>1){
//            $this->assign('page',$page);
//
//        }
//        $this->assign('loginName',$_SESSION['loginName']);
//        $this->assign('data',$file_contents['data']['records']);
        $this->display('contract_manage');
    }






//合同删除
    public function contractDel(){

        $contractId=$_POST['id'];
        $data =array(
            'contractId' => $contractId,

        );  //定义参数
        $url = INTERFACE_ADDRESS.'/api/contract/delContractTemplate';




        $header = array('bAccessToken:'.$_SESSION['bAccessToken'],'language:zh','region:GZ');
        $response = $this->tocurlPost($url, $header,$data);
        $info = json_decode($response, true);



//            print_r($info);

        if($info['code']==200){
            ajaxReturn(10);
        }else{
            ajaxReturn(20);
        }

    }




    /**
     **发布编辑合同
     **/
//    public function contractAdd()
//    {
//
//        $id=$_GET['id'];
//
//
//        //获取印章列表
//        $page=$_REQUEST['pages']?(int)$_REQUEST['pages']:1;
//        $url = INTERFACE_ADDRESS.'/api/seal/sealListBy?pageSize=3&pages='.$page;
//
//
//        $header = array('bAccessToken:'.$_SESSION['bAccessToken'],'language:zh','region:GZ');
//        $response = $this->tocurlGet($url, $header);
//        $file_contents = json_decode($response, true);
//
//      $sealList =  $file_contents['data']['records'];
//
//      $this->assign('sealList',$sealList);
////        print_r($sealList);
////var_dump($id);
//        if($_SERVER["REQUEST_METHOD"] === "POST"){
//
//            $name=$_POST['name'];
//            $select=$_POST['seal'];
//            $content=strip_tags($_POST['content']);
//
//
//            if(empty($name)){
//
//                echo "<script>alert('标题不能为空,请重新输入！')</script>";
////                return false;
//            }
//
//
//            if(empty($content)){
//
//                echo "<script>alert('内容不能为空,请重新输入！')</script>";
////                return false;
//            }
//
////          var_dump($_POST);exit;
//            $data =array(
//                'name' => $name,
//                'sealId'  => $select,
//                'content'  => $content,
//            );  //定义参数
//
//            if($id>0){ //编辑
//                $data['contractId']=$id;
//                $url = INTERFACE_ADDRESS.'/api/contract/editContractTemplate';
//
//
//                $header = array('bAccessToken:'.$_SESSION['bAccessToken'],'language:zh','region:GZ');
//                $response = $this->tocurlPost($url, $header,$data);
//                $info = json_decode($response, true);
//
//
////          print_r($info);exit;
//                if($info['code']==200){
//                    echo "<script>alert('编辑成功')</script>";
//
////                    header('Location:http://localhost/Bside/index.php/Admin/Admin/contractManage.html');
//                    header('Location:http://'. $_SERVER['HTTP_HOST'].'/Admin/Admin/contractManage');
//                }
//
//            }else{//发布
//
//
////
////                $url = INTERFACE_ADDRESS.'/api/contract/addContractTemplate';
////
////                $header = array('bAccessToken:'.$_SESSION['bAccessToken'],'language:zh','region:GZ');
////                $response = $this->tocurlPost($url, $header,$data);
////                $info = json_decode($response, true);
////
////                print_r($info);
////
////                if($info['code']==200){
////                    echo "<script>alert('保存成功')</script>";
//////                    header('Location:http://localhost/Bside/index.php/Admin/Admin/contractManage.html');
////                    header('Location:http://'. $_SERVER['HTTP_HOST'].'/Admin/Admin/contractManage');
////                }
//
//
//
//
//
//
//                header('Location:http://'. $_SERVER['HTTP_HOST'].'/Admin/Admin/contractAddStep2');
//            }
//
//        }//end 编辑发布提交表单
//
//
//        if($id) {  //编辑
//            $data =array(
//                'contractId' => $id,
//
//            );  //定义参数
//            $url = INTERFACE_ADDRESS.'/api/contract/contractTemplateById';

//
//
//            $header = array('bAccessToken:'.$_SESSION['bAccessToken'],'language:zh','region:GZ');
//            $response = $this->tocurlPost($url, $header,$data);
//            $info = json_decode($response, true);
//
//
//          print_r($info);
//
//            $this->assign('data',$info['data']);
//
//
//
//
//        }
//        $this->assign('loginName',$_SESSION['loginName']);
//        $this->display('contract_add');
//
//
//    }



    /**
     **发布编辑合同
     **/
    public function contractAdd()
    {
        $contractInfo=array();//储存用户输入的内容

        $id=$_GET['id'];
        $action=$_GET['action'];

        if($id>0){ //编辑  获取页面数据
            $data =array(
                'contractId' => $id,
            );  //定义参数
            $url = INTERFACE_ADDRESS.'/api/contract/contractTemplateById';
            $header = array('bAccessToken:'.$_SESSION['bAccessToken'],'language:zh','region:GZ');
            $response = $this->tocurlPost($url, $header,$data);
            $info = json_decode($response, true);
            print_r($info);

            $this->assign('data',$info['data']);
        }



        if ($action == 'step1') {//合同发布第一步
                //获取印章列表
                $page = $_REQUEST['pages'] ? (int)$_REQUEST['pages'] : 1;
                $url = INTERFACE_ADDRESS . '/api/seal/sealListBy?pageSize=10&pages=' . $page;
                $header = array('bAccessToken:' . $_SESSION['bAccessToken'], 'language:zh', 'region:GZ');
                $response = $this->tocurlGet($url, $header);
                $file_contents = json_decode($response, true);

                $sealList = $file_contents['data']['records'];

                $this->assign('sealList', $sealList);
                print_r($sealList);


            if ($_SERVER["REQUEST_METHOD"] === "POST"){//点击下一步

                        //获取用户输入的数据
                        $name=$_POST['name'];

                        $select=$_POST['seal'];
                        $content=strip_tags($_POST['content']);
                        if(empty($name)){
                            echo "<script>alert('标题不能为空,请重新输入！')</script>";
//                    return false;
                        }
                        if(empty($content)){
                            echo "<script>alert('内容不能为空,请重新输入！')</script>";
//                    return false;
                        }


                        $contractInfo['name']=$name;
                        $contractInfo['select']=$select;
                        $contractInfo['content']=$content;

//                        print_r($contractInfo);

                       session('contractInfo',$contractInfo);//保存第一步用户输入的数据
                        header('Location:http://'. $_SERVER['HTTP_HOST'].'/Admin/Admin/contractAdd/action/step2.html');
                    }

                $this->assign('loginName',$_SESSION['loginName']);
                $this->display('contract_add');

            }//step1 end


            if ($action == 'step2') {//合同发布第二步
//                print_r($_SESSION['contractInfo']);
                if ($_SERVER["REQUEST_METHOD"] === "POST"){ //点击提交
//                    print_r($_REQUEST);exit;
                    //印章数据处理
                   $sealData = doSealData($_REQUEST['sealCoordinate'],$_REQUEST['sealCoordinateLen']);
                   $signData = doSealData($_REQUEST['signCoordinate'],$_REQUEST['signCoordinateLen']);
                   $signatoryData = doSealData($_REQUEST['signatoryCoordinate'],$_REQUEST['signatoryCoordinateLen']);

                    $jsonSealData=json_encode($sealData);
                    $jsonSignData=json_encode($signData);
                    $jsonSignatoryData=json_encode($signatoryData);
                    //print_r($jsonSealData);exit;


                    $data =array(
                        'name' => $_SESSION['contractInfo']['name'],
                        'sealId' => $_SESSION['contractInfo']['select'],
                        'content' => $_SESSION['contractInfo']['content'],
                        'signatoryPst' => $jsonSignatoryData,
                        'sealPst' => $jsonSealData,
                        'signedPst' => $jsonSignData,

                    );  //定义参数
                    $url = INTERFACE_ADDRESS.'/api/contract/addContractTemplate';
                    $header = array('bAccessToken:'.$_SESSION['bAccessToken'],'language:zh','region:GZ');
                    $response = $this->tocurlPost($url, $header,$data);
                    $info = json_decode($response, true);

                    print_r($info);exit;


//                    print_r($_SESSION['contractInfo']);exit;
                }

                $this->assign('contractInfo',$_SESSION['contractInfo']);

                $this->assign('loginName',$_SESSION['loginName']);
                $this->display('contractAddStep2');
            }//step2 end





    }







    /**
     **预览合同
     **/
    public function previewContract(){
        checkLogin();

        $id=$_GET['id'];

        $data =array(
            'contractId' => $id,

        );  //定义参数
        $url = INTERFACE_ADDRESS.'/api/contract/contractTemplateById';
        $header = array('bAccessToken:'.$_SESSION['bAccessToken'],'language:zh','region:GZ');
        $response = $this->tocurlPost($url, $header,$data);
        $info = json_decode($response, true);


//        print_r($info);


        $this->assign('data',$info['data']);
        $this->assign('loginName',$_SESSION['loginName']);
        $this->display('contract_manage_review');
    }



//印章列表
        public function contractSealManage(){
            checkLogin();

            $page=$_REQUEST['pages']?(int)$_REQUEST['pages']:1;
            $url = INTERFACE_ADDRESS.'/api/seal/sealListBy?pageSize='.$this->pagesize.'&pages='.$page;


            $header = array('bAccessToken:'.$_SESSION['bAccessToken'],'language:zh','region:GZ');
            $response = $this->tocurlGet($url, $header);
            $file_contents = json_decode($response, true);

//            $file_contents = json_decode(file_get_contents($url),true);

            print_r($file_contents);

            $totalPage=$file_contents['data']['pages'];

            if($page<1||$page==null||!is_numeric($page))$page=1;
            if($page>=$totalPage)$page=$totalPage;



            $page=  showPage($page,$totalPage,$url='http://xbb.qecity.com/Admin/Admin/contractSealManage.html',$this->pagesize,$file_contents['data']['total']);



            if($totalPage>1){
                $this->assign('page',$page);

            }
            $this->assign('data',$file_contents['data']['records']);



            $this->assign('loginName',$_SESSION['loginName']);
            $this->display('contract_sealManage');
        }


//印章重命名
        public function sealReName(){

            $sealId=$_POST['id'];
            $name=$_POST['name'];

            $data =array(
                'sealId' => $sealId,
                'name' => $name,

            );  //定义参数
            $url = INTERFACE_ADDRESS.'/api/seal/renameSeal';


            $header = array('bAccessToken:'.$_SESSION['bAccessToken'],'language:zh','region:GZ');
            $response = $this->tocurlPost($url, $header,$data);
            $info = json_decode($response, true);




            print_r($info);

            if($info['code']==200){
                  ajaxReturn(10);
            }else{
                ajaxReturn(20);
            }

        }



//印章删除
    public function sealDel(){

        $sealId=$_POST['id'];
        $data =array(
            'sealId' => $sealId,

        );  //定义参数
        $url = INTERFACE_ADDRESS.'/api/seal/delSeal';




        $header = array('bAccessToken:'.$_SESSION['bAccessToken'],'language:zh','region:GZ');
        $response = $this->tocurlPost($url, $header,$data);
        $info = json_decode($response, true);



//            print_r($info);

        if($info['code']==200){
            ajaxReturn(10);
        }else{
            ajaxReturn(20);
        }

    }





    public function dofilter(){
        $filter=$_POST['filterNum'];
        $oldimgsrc=$_POST['oldimgsrc'];
        //将截取后的图片 去掉背景色

//        $jiequ='/home/wwwroot/xbbplatform/Public/tmpImg/jiequ11.jpg';
//        $target='/home/wwwroot/xbbplatform/Public/tmpImg/koutu11.png';

        $jiequ=$oldimgsrc;
        $target='/home/wwwroot/xbbplatform/Public/tmpImg/koutu'.rand(1,9999).'.png';


       $this->picCavern($jiequ,$target,$filter);
//            print_r($target) ;
            return  ajaxReturn($target);

        }



    /**
     **新增印章第一步
     **/
    public function sealAddstep1()
    {
        checkLogin();





        $this->assign('loginName',$_SESSION['loginName']);
        $this->display('picture-add');


    }


    /**
     **新增印章第二步
     **/
    public function sealAddstep2()
    {
        checkLogin();

        $cropData=$_POST['hi'];

        $tit=$_POST['tit'];
        $this->assign('tit',$tit);
        var_dump(I('post.'));
        $arrCropData=explode(',',$cropData);
//        exit;
        $old='/home/wwwroot/xbbplatform/Public/tmpImg/'.$_FILES['file']['name'];
        $ext = substr(strrchr( $_FILES['file']['name'], '.'), 1);//截取后缀名


        $jiequ1='/home/wwwroot/xbbplatform/Public/tmpImg/';
        $jiequname='jiequ';


//            print_r($jiequsrc);


//            print_r($jiequ);exit;
//            print_r($target);exit;
        //                $sealInfo['name']=$name;

//                $sealInfo['jiequ']=$jiequ;
//                $sealInfo['filename']=$_FILES['file']['name'];
//                session('sealInfo',$sealInfo);//保存第一步用户输入的数据

//    print_r($_FILES);exit;

        if(move_uploaded_file($_FILES['file']['tmp_name'],$old)){
//                echo "Successfully!";exit;
            //截取后的图片
        $jiequsrc=    thum_images($old,$arrCropData[2],$arrCropData[3],$jiequ1,$jiequname);


            $jiequsub=substr($jiequsrc,27);
            $newjiequsrc="http://xbb.qecity.com/".$jiequsub;

            $this->assign('jiequsrc',$newjiequsrc);

        }


        if (  $_POST['step2sub']=='提交'){ //点击提交

//            print_r($_REQUEST);exit;

            $koutuimg=$_POST['koutuimg'];
//            http://xbb.qecity.com/
             $koutuSub=substr($koutuimg,22);
             $koutuSrc='/home/wwwroot/xbbplatform/'.$koutuSub;

//            $extension = substr(strrchr( $koutuSrc, '.'), 1);//截取后缀名
            $extension = 'png';//截取后缀名
//

            $a='apple';
            $uploadQiNiu=D('UploadQiNiu');
//            http://xbb.qecity.com/Public/tmpImg/koutu7247.png
            $qiniuName=substr($koutuimg,36);

//            $result =  $uploadQiNiu->uploadQiNiu($_FILES['file']['tmp_name'],$key=$a.$extension.$name.'.'.$extension);
            $result =  $uploadQiNiu->uploadQiNiu($koutuSrc,$key=$a.$qiniuName);
            $src=$uploadQiNiu->getQiNiuDownloadUrlOpen($a.$qiniuName);//图片地址
//print_r($src);exit;

            $data =array(
                'name' =>$tit,
                'url'=>$src
            );  //定义参数

            $url = INTERFACE_ADDRESS.'/api/seal/addSeal';
            $header = array('bAccessToken:'.$_SESSION['bAccessToken'],'language:zh','region:GZ');
            $response = $this->tocurlPost($url, $header,$data);
            $info = json_decode($response, true);

print_r($info);

                if($info['code']=='200'){
                    header('Location:http://'. $_SERVER['HTTP_HOST'].'/Admin/Admin/contractSealManage');
                }else{
//                echo "<script>alert('账户或密码错误')</script>";
                    exit('新增印章失败！点击此处 <a href="javascript:history.back(-1);">返回</a> 重试');
                }


        }









        $this->assign('loginName',$_SESSION['loginName']);
        $this->display('SeaAddStep2');


    }











//已发送列表

    public function contractSend(){
        checkLogin();
        $page=$_REQUEST['pages']?(int)$_REQUEST['pages']:1;
        $url = INTERFACE_ADDRESS.'/api/contract/contractSentList?pageSize='.$this->pagesize.'&pages='.$page;
//        $file_contents = json_decode(file_get_contents($url),true);

        $header = array('bAccessToken:'.$_SESSION['bAccessToken'],'language:zh','region:GZ');
        $response = $this->tocurlGet($url, $header);
        $file_contents = json_decode($response, true);


//        print_r($file_contents);

        $totalPage=$file_contents['data']['pages'];

        if($page<1||$page==null||!is_numeric($page))$page=1;
        if($page>=$totalPage)$page=$totalPage;



        $page=  showPage($page,$totalPage,$url='http://xbb.qecity.com/Admin/Admin/contractSend.html',$this->pagesize,$file_contents['data']['total']);


        if($totalPage>1){
            $this->assign('page',$page);

        }
        $this->assign('data',$file_contents['data']['records']);
        $this->assign('loginName',$_SESSION['loginName']);
        $this->display('contract_send');
    }



//已签署

    public function contracSign(){
        checkLogin();
        $page=$_REQUEST['pages']?(int)$_REQUEST['pages']:1;
        $url = INTERFACE_ADDRESS.'/api/contract/contractSignedList?pageSize='.$this->pagesize.'&pages='.$page;
//        $file_contents = json_decode(file_get_contents($url),true);


        $header = array('bAccessToken:'.$_SESSION['bAccessToken'],'language:zh','region:GZ');
        $response = $this->tocurlGet($url, $header);
        $file_contents = json_decode($response, true);

        print_r($file_contents);

        $totalPage=$file_contents['data']['pages'];

        if($page<1||$page==null||!is_numeric($page))$page=1;
        if($page>=$totalPage)$page=$totalPage;




        $page=  showPage($page,$totalPage,$url='http://xbb.qecity.com/Admin/Admin/contracSign.html',$this->pagesize,$file_contents['data']['total']);


        if($totalPage>1){
            $this->assign('page',$page);

        }
        $this->assign('data',$file_contents['data']['records']);
        $this->assign('loginName',$_SESSION['loginName']);
        $this->display('contract_sign');
    }




//接口信息

    public function interfaceManage(){
        checkLogin();
        $page=$_REQUEST['pages']?(int)$_REQUEST['pages']:1;
        $url = INTERFACE_ADDRESS.'/api/apiAuth/apiAuthList?pageSize='.$this->pagesize.'&pages='.$page;
//        $file_contents = json_decode(file_get_contents($url),true);

        $header = array('bAccessToken:'.$_SESSION['bAccessToken'],'language:zh','region:GZ');
        $response = $this->tocurlGet($url, $header);
        $file_contents = json_decode($response, true);



        $totalPage=$file_contents['data']['pages'];

        if($page<1||$page==null||!is_numeric($page))$page=1;
        if($page>=$totalPage)$page=$totalPage;



        $page=  showPage($page,$totalPage,$url='http://xbb.qecity.com/Admin/Admin/interfaceManage.html',$this->pagesize,$file_contents['data']['total']);
        print_r($file_contents);

        $this->assign('page',$page);
        $this->assign('data',$file_contents['data']['records']);
        $this->assign('total',$file_contents['data']);
        $this->assign('loginName',$_SESSION['loginName']);
        $this->display('interface_manage');
    }





    //交易记录

    public function financeManage(){
        checkLogin();

        $url = INTERFACE_ADDRESS.'/api/fiance/records';
        $header = array('bAccessToken:'.$_SESSION['bAccessToken'],'language:zh','region:GZ');
        $response = $this->tocurlGet($url, $header);
        $file_contents = json_decode($response, true);


//        print_r($file_contents);

        //获取收费金额
        $data=$file_contents['data'];

        $total=count($data);






        foreach ($data  as $k=>$v){
            $url = INTERFACE_ADDRESS.'/api/fiance/unfilledOrderStatistics?projectType='.$v['category'];
            $header = array('bAccessToken:'.$_SESSION['bAccessToken'],'language:zh','region:GZ');
            $response = $this->tocurlGet($url, $header);
            $totalfee = json_decode($response, true);
            $money_sum=$totalfee['data']['money_sum'];
            $data[$k]['fee']=$money_sum;




        }
        print_r($data);

        $this->assign('totalfee',$totalfee['data']);

        $this->assign('total',$total);
        $this->assign('data',$data);
        $this->assign('loginName',$_SESSION['loginName']);
        $this->display('finance_manage');
    }

    //交易明细

    public function finance_records(){
        checkLogin();
        $page=$_REQUEST['pages']?(int)$_REQUEST['pages']:1;
        $url = INTERFACE_ADDRESS.'/api/fiance/orderDetails?rows='.$this->pagesize.'&pages='.$page;
        $header = array('bAccessToken:'.$_SESSION['bAccessToken'],'language:zh','region:GZ');
        $response = $this->tocurlGet($url, $header);
        $file_contents = json_decode($response, true);


        $totalPage=$file_contents['data']['counts']/2;
        if($totalPage<1){
            $totalPage=1;
        }

        if($page<1||$page==null||!is_numeric($page))$page=1;
        if($page>=$totalPage)$page=$totalPage;




        $page=  showPage($page,$totalPage,$url='http://xbb.qecity.com/Admin/Admin/financeManage.html',$this->pagesize,$file_contents['data']['total']);


        $this->assign('page',$page);

        print_r($file_contents);
        //获取保全号
        $data=$file_contents['data'];
        foreach ($data  as $k=>$v){
            $url = INTERFACE_ADDRESS.'/api/fiance/certificateNumber?order='.$v['odr_number'];
            $header = array('bAccessToken:'.$_SESSION['bAccessToken'],'language:zh','region:GZ');
            $response = $this->tocurlGet($url, $header);
            $baoquanNum = json_decode($response, true);


            $data[$k]['baoquanNum']=$baoquanNum['data'];

        }


//        print_r($data);



        //获取消费金额
//        $data=$file_contents['data'];
//        foreach ($data  as $k=>$v){
//            $url = INTERFACE_ADDRESS.'/api/fiance/unfilledOrderStatistics?projectType='.$v['category'];
//            $header = array('bAccessToken:'.$_SESSION['bAccessToken'],'language:zh','region:GZ');
//            $response = $this->tocurlGet($url, $header);
//            $totalfee = json_decode($response, true);
//            $money_sum=$totalfee['data']['money_sum'];
//            $data[$k]['fee']=$money_sum;
//
//        }







        $this->assign('data',$data);



        $this->assign('loginName',$_SESSION['loginName']);
        $this->display('finance_records');
    }





    //修改密码

    public function safeCenter(){
        checkLogin();
        $this->assign('loginName',$_SESSION['loginName']);
        $this->display('safe_center');
    }



    //修改密码Ajax

    public function safeCenterAjax(){



            $oldPw=$_POST['oldPw'];
            $newPw=$_POST['newPw'];
            $conPw=$_POST['conPw'];
            $data =array(
                'oldPsw' => $oldPw,
                'newPsw'  => $newPw,
                'confirmPsw'  => $newPw,
            );  //定义参数
            $url = INTERFACE_ADDRESS.'/api/user/bModifyPassword';

        $header = array('bAccessToken:'.$_SESSION['bAccessToken'],'language:zh','region:GZ');


        $response = $this->tocurlPost($url, $header, $data);
        $info= json_decode($response, true);
//        var_dump($info);die;

            if($info['code']=='200'){//修改成功
                ajaxReturn(10);

            }else {// 旧密码错误
                ajaxReturn(20);
            }



    }





    //权限列表

    public function authControl(){
        checkLogin();

        $page=$_REQUEST['pages']?(int)$_REQUEST['pages']:1;
        $url = INTERFACE_ADDRESS.'/api/authUser/authUserList?pageSize='.$this->pagesize.'&pages='.$page;
//        $file_contents = json_decode(file_get_contents($url),true);

        $header = array('bAccessToken:'.$_SESSION['bAccessToken'],'language:zh','region:GZ');
        $response = $this->tocurlGet($url, $header);
        $file_contents = json_decode($response, true);


        print_r($file_contents);

        $totalPage=$file_contents['data']['pages'];

        if($page<1||$page==null||!is_numeric($page))$page=1;
        if($page>=$totalPage)$page=$totalPage;




        $page=  showPage($page,$totalPage,$url='http://xbb.qecity.com/Admin/Admin/authControl.html',$this->pagesize,$file_contents['data']['total']);


        if($totalPage>1){
            $this->assign('page',$page);

        }
        $this->assign('data',$file_contents['data']['records']);
        $this->assign('total',$file_contents['data']['total']);


        $this->assign('loginName',$_SESSION['loginName']);
        $this->display('auth_control');
    }





//确认添加权限
    public function sureAddPow(){

        $userName=$_POST['userName'];
        $phoneNumber=$_POST['iphone'];

        $data =array(
            'userName' => $userName,
            'phoneNumber' => $phoneNumber,

        );  //定义参数
        $url = INTERFACE_ADDRESS.'/api/authUser/addAuthUser';



        $header = array('bAccessToken:'.$_SESSION['bAccessToken'],'language:zh','region:GZ');
        $response = $this->tocurlPost($url, $header,$data);
        $info = json_decode($response, true);
//            print_r($info);

        if($info['code']==200){
            ajaxReturn(10);
        }else{
            ajaxReturn(20);
        }

    }



 //重置key
    public function resetKey(){

        $url = INTERFACE_ADDRESS.'/api/apiAuth/resetKey';
//        $file_contents = json_decode(file_get_contents($url),true);

        $header = array('bAccessToken:'.$_SESSION['bAccessToken'],'language:zh','region:GZ');
        $response = $this->tocurlGet($url, $header);
        $file_contents = json_decode($response, true);

//        print_r($file_contents);
        if($file_contents['code']=='200'){
            ajaxReturn(10);
        }else{
            ajaxReturn(20);
        }


    }



    //权限删除
    public function authDel(){

        $contractId=$_POST['id'];
        $data =array(
            'contractId' => $contractId,

        );  //定义参数
        $url = INTERFACE_ADDRESS.'/api/contract/delContractTemplate';




        $header = array('bAccessToken:'.$_SESSION['bAccessToken'],'language:zh','region:GZ');
        $response = $this->tocurlPost($url, $header,$data);
        $info = json_decode($response, true);



//            print_r($info);

        if($info['code']==200){
            ajaxReturn(10);
        }else{
            ajaxReturn(20);
        }

    }





    /**
     * POST发送数据
     * @param String $url     请求的地址
     * @param Array  $header  自定义的header数据
     * @param Array  $content POST的数据
     * @return String
     */
    public function tocurlPost($url, $header, $content){
        $ch = curl_init();
        if(substr($url,0,5)=='https'){
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 跳过证书检查
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, true);  // 从证书中检查SSL加密算法是否存在
        }
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($content));
        $response = curl_exec($ch);
        if($error=curl_error($ch)){
            die($error);
        }
        curl_close($ch);
        return $response;
    }

    /**
     * GET发送数据
     * @param String $url     请求的地址
     * @param Array  $header  自定义的header数据
     * @param Array  $content POST的数据
     * @return String
     */
    public function tocurlGet($url, $header){
        $ch = curl_init();
        if(substr($url,0,5)=='https'){
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 跳过证书检查
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, true);  // 从证书中检查SSL加密算法是否存在
        }
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $header);

        $response = curl_exec($ch);
        if($error=curl_error($ch)){
            die($error);
        }
        curl_close($ch);
        return $response;
    }



    public function test(){


        $source=APP_PATH."images/icond.png";
//        print_r($source);exit;
        $target=APP_PATH."testimg/123.png";
        $filter='13';
//        $PicCaculate=D('PicCaculate');
//        $PicCaculate->picCavern($source,$target,$filter);

        $this->picCavern($source,$target,$filter);
    }



    public function test1(){


        $this->display('test1');
    }




    public function picCavern($source,$target,$filter=1)
    {
        //设置过滤器
        switch($filter){
            case 1:$rV=160;$otherV=160;break;
            case 2:$rV=120;$otherV=70;break;
            case 3:$rV=150;$otherV=60;break;
            case 4:$rV=200;$otherV=50;break;
            case 5:$rV=225;$otherV=40;break;
            //蓝色系过滤器
            case 6:$bV=100;$otherV=50;break;
            case 7:$bV=150;$otherV=60;break;
            case 8:$bV=200;$otherV=70;break;
            case 9:$bV=210;$otherV=80;break;
            case 10:$bV=225;$otherV=90;break;
            //黑色系
            case 11:$rV=$gV=$bV=40;break;
            case 12:$rV=$gV=$bV=50;break;
            case 13:$rV=$gV=$bV=60;break;
            case 14:$rV=$gV=$bV=80;break;
            case 15:$rV=$gV=$bV=100;break;
        }
        $srcSize=$this->getPicSize($source);
        $srcW=$srcSize[0];
        $srcH=$srcSize[1];
        $srcType=$this->getPicType($source);
        $bgImg=$this->getImg($source);//原图
        $white=imagecolorallocate($bgImg,255,255,255);//指定白色为需要干掉的

        for($x=0;$x<$srcW;$x++){
            for($y=0;$y<$srcH;$y++){
                $rgb=imagecolorat($bgImg,$x,$y);
                $currentPix=imagecolorsforindex($bgImg,$rgb);//取得当前像素 rgb  和 alpha通道值
                //var_dump($currentPix);
                /*$r=($rgb>>16)&0xFF;//按位右移内存获取rgb的单独颜色值
                $g=($rgb>>8)&0xFF;
                $b=$rgb&0xFF;*/
                $r=$currentPix['red'];//红色系
                $g=$currentPix['green'];//绿色系
                $b=$currentPix['blue'];//蓝色系
                $alpha=$currentPix['alpha'];//α通道
                if($alpha>=118){//如果是接近透明色
                    imagefill($bgImg,$x,$y,$white); //在透明图层上覆盖填充需要干掉的颜色
                }else{//如果不透明则判断色系
                    if($filter>0&&$filter<6){//红色系
                        if(!($r>=$rV&&$g<=$otherV&&$b<=$otherV)){
                            imagefill($bgImg,$x,$y,$white); //在其他杂色上覆盖填充需要干掉的颜色
                        }
                    }elseif($filter>=6&&$filter<=10){//蓝色系
                        if(!($b>=$bV&&$r<=$otherV&&$g<=$otherV)){
                            imagefill($bgImg,$x,$y,$white); //在其他杂色上覆盖填充需要干掉的颜色
                        }
                    }elseif($filter>10&&$filter<=15){//黑色系
                        if(!($r<=$rV&&$g<=$gV&&$b<=$bV)){
                            imagefill($bgImg,$x,$y,$white); //在其他杂色上覆盖填充需要干掉的颜色
                        }
                    }
                }
            }
        }
        imagecolortransparent($bgImg,ImageColorAllocate($bgImg,255,255,255));//去掉白色
        header('content-type:image/png');
        imagepng($bgImg,$target);
        imagedestroy($bgImg);
    }



    /*
      *获取图片尺寸
      */
    private function getPicSize($source){
        return  getimagesize($source);
    }

    /*
    *获取图片扩展名类型
    */
    private function getPicType($source){
        $pictype=$this->getPicSize($source);
        $pictype=explode('/',$pictype['mime']);
        $pictype=$pictype[1];
        return $pictype;
    }

    /*
    *图片创建至内存
    */
    private function getImg($source){
        $stype=$this->getPicType($source);
        switch($stype){
            case 'gif':$simg=imagecreatefromgif($source);break;
            case 'jpeg':$simg=imagecreatefromjpeg($source);break;
            case 'png':$simg=imagecreatefrompng($source);break;
        }
        return $simg;
    }







}